package com.example.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.entity.Person;
import com.example.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class PersonController {
    @Autowired
    private PersonService personService;

    @RequestMapping("findPage")
    public String page(Page page, Model model,String name,String dname){
        LambdaQueryWrapper<Person> queryWrapper = new LambdaQueryWrapper<>();
        if (name==null){
            name="";
        }
        if (dname==null){
            dname="";
        }
        queryWrapper.like(Person::getName,name);
        queryWrapper.like(Person::getDname,dname);
        Page<Person> page1=new Page(page.getCurrent(),5);
        Page<Person> pageInfo=personService.findPage(page1,queryWrapper);
        model.addAttribute("persons",pageInfo);
        return "person";
    }


    @RequestMapping("delete")
    public String del(Integer id){
        personService.del(id);
        return "redirect:/findPage";
    }

}
